#!/usr/bin/perl
#
# Remove empty person records from the database
#
# These are created by a bug in the userupdate(adm) script when applied to
# entries with no person record
#
use Counter;
use Fcntl;

$users = Counter::open(O_RDWR);
$persons = Counter::openfile("persons");
@recs = $persons->select("placeid='XW' and name = '' and started = ''");
print "Got ", @recs + 0, " records\n";
$skipcount = 0;
$deletecount = 0;
for $rec (@recs) {
    if ($$rec{ident} !~ /userupdate.cgi.*user=/) {
	print "Skipping, not userupdate ", $rec->key(), "\n";
	++ $skipcount;
# may-publish tends towards being set after people have deleted themselves
#    } elsif ($$rec{"may-publish"}) {
#	print "Skipping, may-publish ", $rec->key(), "\n";
#	++ $skipcount;
    } elsif ($$rec{usage}) {
	print "Skipping, usage $$rec{usage}: ", $rec->key(), "\n";
	++ $skipcount;
    } else {
	print "Deleting ", $rec->key(), "\n";
	$rec->delete();
	++ $deletecount;
    }
}
print "$deletecount deletes, $skipcount skips\n";

